<?php
	include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/conn_mdb.php");
	include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/conn_db.php");
	include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/Utils.php");
	if(isset($_COOKIE["user"])){
		$type = isset($_REQUEST["type"]) ? $_REQUEST["type"] : 0;
		if($type === 0 && isset($_GET["index"])){
			$index = $_GET["index"];
			if($index > 0){
				echo Utils::getLastname($index);
			}
		}else if($type == 1 && isset($_GET["left"]) && isset($_GET["right"])){
			$left = $_GET["left"] ? $_GET["left"] : 0;
			$right = $_GET["right"] ? $_GET["right"] : 0;
			echo Utils::getHome($left, $right);
		}else if($type == 2 && isset($_GET["gen_type"]) && isset($_GET["code"])){
			$gen_type = $_GET["gen_type"];
			$code = $_GET["code"];
			echo Utils::getPaParent($code, $gen_type);
		}else if($type == 3 && isset($_POST["gen"]) && isset($_POST["cate_name"]) && isset($_POST["pa_type"]) && isset($_POST["pa_name"]) && isset($_POST["home"])){
			$gen = trim($_POST["gen"]);
			$cate_name = trim($_POST["cate_name"]);
			$cate_hname = isset($_POST["cate_hname"]) ? trim($_POST["cate_hname"]) : "";
			$pa_type = trim($_POST["pa_type"]);
			$pa_name = trim($_POST["pa_name"]);
			$pa_hname = isset($_POST["pa_hname"]) ? trim($_POST["pa_hname"]) : "";
			$parent = isset($_POST["parent"]) ? trim($_POST["parent"]) : "";
			$home = trim($_POST["home"]);
			echo Utils::insertPa($gen, $cate_name, $cate_hname, $pa_type, $pa_name, $pa_hname, $parent, $home);
		}else{
			echo 111;
		}
	}else{
		echo json_encode(array("status"=>"logout"));
	}
?>
